<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<div class="panel_container">
    <div class="panel">
        <form id="formId" method="post" action="${ctx}/loan/addLoan">
            <div class="panel_header">
                <div><h2>添加贷款</h2></div>
            </div>
            <div class="panel_body">
                <div>
                    <div>
                        <div class="info_item"><span>金融机构编码:</span><b>*</b>
                            <select name="orgId" id="orgId">
                                <option value="">--请选择--</option>
                                <c:forEach var="entry" items="${orgList}">
                                    <option value="${entry.id}" >${entry.orgName}</option>
                                </c:forEach>
                            </select>
                        </div>

                        <div class="info_item"><span>企业组织机构代码:</span>
                            <input type="text" name="zzjgdm" maxlength="10" />
                        </div>

                        <div class="info_item"><span>企业名称:</span><b>*</b>
                            <input type="text" name="qymc" maxlength="80" />
                        </div>

                    </div>

                    <div class="noday">
                        <div class="info_item"><span>数据时间:</span><b>*</b>
                            <input type="text" name="sjsj"  id="sjsj" readonly="true"/>
                        </div>

                        <div class="info_item"><span>内部对企业评级结果:</span>
                            <input type="text" name="nbpj" maxlength="10" />
                        </div>

                        <div class="info_item"><span>外部对企业评级:</span>
                            <input type="text" name="wbpj" maxlength="10"  />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>贷款合同号:</span>
                            <input type="text" name="dkhth" maxlength="50" />
                        </div>

                        <div class="info_item"><span>贷款借据号:</span><b>*</b>
                            <input type="text" name="dkjjh" maxlength="20" />
                        </div>

                        <div class="info_item"><span>币种:</span><b>*</b>
                            <tags:select name="bz" id="bz" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID = 9 "  />
                        </div>

                    </div>

                    <div>
                        <div class="info_item"><span>基本利率（%）:</span>
                            <input type="text" name="jbll" maxlength="7"/>
                        </div>

                        <div class="info_item"><span>利率浮动（%）:</span>
                            <input type="text" name="llfd" maxlength="7"/>
                        </div>

                        <div class="info_item"><span>实际利率（%）:</span><b>*</b>
                            <input type="text" name="sjll"   maxlength="7"/>
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>贷款类别:</span><b>*</b>
                            <tags:select name="dklb" id="dklb" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID =10 "  />
                        </div>

                        <div class="info_item"><span>贷款发放金额:</span>
                            <input type="text" name="dkffje" />
                        </div>

                        <div class="info_item"><span>贷款余额:</span><b>*</b>
                            <input type="text" name="dkye"  />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>放款日期:</span><b>*</b>
                            <input type="text" name="fkrq" id="fkrq" readonly="true"/>
                        </div>

                        <div class="info_item"><span>到期日期:</span><b>*</b>
                            <input type="text" name="dqrq" id="dqrq" readonly="true"/>
                        </div>

                        <div class="info_item"><span>展期日期:</span>
                            <input type="text" name="zqrq" id="zqrq" readonly="true"/>
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>担保方式:</span><b>*</b>
                            <select name="dbfs" id="dbfs">
                                <option value="">--请选择--</option>
                                <option value="保证">保证</option>
                                <option value="质押">质押</option>
                                <option value="抵押">抵押</option>
                                <option value="混合">混合</option>
                                <option value="信用">信用</option>
                            </select>
                        </div>

                        <div class="info_item"><span>五级分类:</span><b>*</b>
                            <tags:select name="wjfl" id="wjfl" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID =12 "  />
                        </div>

                        <div class="info_item"><span>欠息金额:</span>
                            <input type="text" name="qxje" />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>保证金额:</span>
                            <input type="text" name="bzje" />
                        </div>
                        <div class="info_item"><span>抵押金额:</span>
                            <input type="text" name="dyje" />
                        </div>
                        <div class="info_item"><span>质押金额:</span>
                            <input type="text" name="zyje"  />
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>抵押明细:</span>
                            <input class="text_large" type="text" name="dymx" maxlength="150" width="200"/>
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>质押明细:</span>
                            <input class="text_large" type="text" name="zymx" maxlength="150" width="200"/>
                        </div>
                    </div>
                    <div>

                    </div>
                    <div class="info_item"><span>保证明细:</span>
                        <input class="text_large" type="text" name="bzmx" maxlength="150" width="200"/>
                    </div>

                </div>
            </div>
            <div class="panel_footer">
                <div>
                    <input type="submit" value="保存" class="btn_blue" id="btn_save"/>
                    <input type="button" value="返回" class="btn_blue" id="btn_back"/>
                </div>
            </div>
        </form>
    </div>
</div>
<style type="text/css">
    .noday .ui-datepicker-calendar {
        display: none;
    }

    .ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year {
        width: 44%;
    }

    .tablewrapper table#example {
        width: 1024px !important;
    }
</style>

<script type="text/javascript">

    function goBack(){
        linkTo("${ctx}/loan/toLoan");
    }

    $(function () {
        $("#sjsj").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yymm',
            beforeShow:function(input, inst) {
                inst.dpDiv.addClass('noday')
            },
            onChangeMonthYear: function (year, month, inst) {
                var selected_month = month-1;
                var selected_year = year;
                $(this).datepicker('setDate', new Date(selected_year, selected_month, 1));
            }
        });


        $('#fkrq').datepicker(
                {
                    beforeShow:function(input, inst) {
                        inst.dpDiv.removeClass('noday')
                    }
                }
        );
        $('#dqrq').datepicker(
                {
                    beforeShow:function(input, inst) {
                        inst.dpDiv.removeClass('noday')
                    }
                }
        );
        $('#zqrq').datepicker(
                {
                    beforeShow:function(input, inst) {
                        inst.dpDiv.removeClass('noday')
                    }
                }
        );

        $("#btn_back").bind("click",goBack);

        $("#formId").validate({
            rules:{
                qymc: "required",
                bz:"required",
                sjsj:"required",
                dkjjh:"required",
                dklb:"required",
                fkrq:"required",
                dqrq:"required",
                dbfs:"required",
                wjfl:"required",
                jbll:{
                    number:true,
                    min:0,
                    max:99.9999
                },
                llfd:{
                    number:true,
                    min:0,
                    max:99.9999
                },
                sjll:{
                    required:true,
                    number:true,
                    min:0,
                    max:99.9999
                },
                dkffje:{
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                dkye:{
                    required:true,
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                bzje:{
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                dyje:{
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                zyje:{
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                qxje:{
                    number:true,
                    min:0,
                    max:9999999999999.99
                }

            },
            messages:{
                qymc:"企业名称不能为空",
                bz:"币种不能为空",
                sjsj:"数据时间不能为空",
                dkjjh:"贷款借据号不能为空",
                dklb:"贷款类别不能为空",
                fkrq:"放款日期不能为空",
                dqrq:"到期日期不能为空",
                dbfs:"担保方式不能为空",
                wjfl:"五级分类不能为空",
                jbll:{
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大值99.9999"
                },
                llfd:{
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大值99.9999"
                },
                sjll:{
                    number:"必须是数字",
                    required:"实际利率不能为空",
                    min:"最小值0",
                    max:"最大值99.9999"
                },
                dkffje:{
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大值9999999999999.99"
                },
                dkye:{
                    number:"必须是数字",
                    required:"贷款余额不能为空",
                    min:"最小值0",
                    max:"最大值9999999999999.99"
                },
                dyje:{
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大值9999999999999.99"
                },
                zyje:{
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大值9999999999999.99"
                },
                qxje:{
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大9999999999999.99"
                }

            },
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    success: function(response) {
                        $.prompt("保存成功");
                        window.setTimeout(function(){
                            goBack();
                        },2000);
                    },

                    error: function(response){
                        $.prompt("保存失败:"+response,"错误");
                    }
                });
            }
        });
    });

</script>

